package com.v2.k35;


import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * 测试手动merge beanDefinition
 */
public class Test {

	public static void main(String[] args) {

		AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();

		GenericBeanDefinition genericBeanDefinition1 = (GenericBeanDefinition)BeanDefinitionBuilder.genericBeanDefinition(User.class).getBeanDefinition();
		genericBeanDefinition1.setScope("prototype");

		GenericBeanDefinition genericBeanDefinition2 = (GenericBeanDefinition)BeanDefinitionBuilder.genericBeanDefinition(Student.class).getBeanDefinition();
		genericBeanDefinition2.setParentName("kzx");

		//注册bd
		applicationContext.registerBeanDefinition("kzx", genericBeanDefinition1);
		applicationContext.registerBeanDefinition("kzxxxx", genericBeanDefinition2);

		//好像这里写子类的名字也可以合并   如用kzxxxx
		RootBeanDefinition rootBeanDefinition = (RootBeanDefinition)applicationContext.getDefaultListableBeanFactory().getMergedBeanDefinition("kzxxxx");
		applicationContext.registerBeanDefinition("mergeKzx", rootBeanDefinition);
		applicationContext.refresh();

		System.out.println(applicationContext.getBean("kzxxxx"));
		System.out.println(applicationContext.getBean("kzxxxx"));
		System.out.println(applicationContext.getBean("kzxxxx"));

	}

}
